function deleteChecked(){
	var request=new XMLHttpRequest();
	request.onreadystatechange=function(){
		if(request.readyState==4){
			if(!(request.status==200)){
				alert("database error");
			}else{
				document.location.reload(true);
			}
		}
	};
	request.open("GET","PlanningHandler?reason=deleteAll",true);
	request.send();
}

function saveCurrentState(){
	var mtable=document.getElementById("taskList");
	var s="";
	for(var i=1;i<mtable.rows.length;i++){
		if(mtable.rows[i].cells[0].childNodes[0].checked){
			s+=mtable.rows[i].cells[0].childNodes[0].name+","+
				"checked,"+
				mtable.rows[i].cells[mtable.rows[i].cells.length-1].childNodes[0].value+",";
		}else{
			s+=mtable.rows[i].cells[0].childNodes[0].name+","+
			","+
			mtable.rows[i].cells[mtable.rows[i].cells.length-1].childNodes[0].value+",";
		}
	}
	
	var request=new XMLHttpRequest();
	request.onreadystatechange=function(){
		if(request.readyState==4){
			if(!(request.status==200)){
				alert("database error");
			}
		}
	};
	request.open("POST","PlanningHandler?reason=saveState",true);
	request.send(s);
}

function estimateSH(o,c){
	if(c.checked){
		o.cells[o.cells.length-1].childNodes[0].style.visibility="visible";
	}else{
		o.cells[o.cells.length-1].childNodes[0].style.visibility="hidden";
	}
}

function sendEmail(){
	saveCurrentState();
	var mtable=document.getElementById("taskList");
	var s="";
	for(var i=0;i<mtable.rows.length;i++){
		if(mtable.rows[i].cells[0].childNodes[0].checked){
			s+=mtable.rows[i].cells[0].childNodes[0].name+",";
		}
	}
	var email=prompt("Send to:");
	var request=new XMLHttpRequest();
	request.onreadystatechange=function(){
		if(request.readyState==4){
			if(!(request.status==200)){
				alert("database error");
			}
		}
	};
	request.open("POST","PlanningHandler?reason=sendEmail&recipient="+email,true);
	request.send(s);
}

function addToBoard(){
	//saveCurrentState();
	var mtable=document.getElementById("taskList");
	var s="";
	for(var i=0;i<mtable.rows.length;i++){
		if(mtable.rows[i].cells[0].childNodes[0].checked){
			s+=mtable.rows[i].cells[0].childNodes[0].name+",";
		}
	}
	if(s!=""){
		var request=new XMLHttpRequest();
		
		request.onreadystatechange=function(){
			if(request.readyState==4){
				if(!(request.status==200)){
					alert("database error");
				}else if(parent!=null){
					parent.document.getElementById("iframe_frame_Board").src=
						parent.document.getElementById("iframe_frame_Board").src;
				}
			}
			
		};
		request.open("POST","PlanningHandler?reason=addToBoard",true);
		request.send(s);
	}
}
